function SYSTEM ()  
{
    this.cpu = new CPU();
    this.rom = new ROM();
    this.cpuMem = null; 
    
    // this.ppuMem = 
    // this.sprMem = 
    
    this.loadRom = function () 
    {
	var input = document.getElementById("cartridge");
	var file=input.files[0];
	var reader = new FileReader();
	function load() {
	    System.rom.init(reader.result);
	    var mappertype = System.rom.mapper;
	    if(mappertype==0)
	    {
		System.mapper = new Mapper0();
	    };
	    System.mapper.init();
	    dumpMemoryMap(System.mapper);
	};

	function errorHandler(evt) {
	    switch(evt.target.error.code) {
	    case evt.target.error.NOT_FOUND_ERR:
		alert('File Not Found!');
		break;
	    case evt.target.error.NOT_READABLE_ERR:
		alert('File is not readable');
		break;
	    case evt.target.error.ABORT_ERR:
		break; // noop
	    default:
		alert('An error occurred reading this file.');
	    };
	};
	reader.onerror = errorHandler;
	reader.onload = load;
	reader.readAsBinaryString(file);
    };



    this.reset = function ()
    {
	
    };    
};

var System = new SYSTEM();



